package com.bjpowernode.service.impl;

import com.alibaba.excel.EasyExcel;
import com.bjpowernode.common.constant.Constant;
import com.bjpowernode.entity.TClue;
import com.bjpowernode.core.listener.ClueExcelListener;
import com.bjpowernode.entity.query.BaseQuery;
import com.bjpowernode.mapper.TClueMapper;
import com.bjpowernode.entity.query.ClueExcel;
import com.bjpowernode.service.ClueService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ClueServiceImpl implements ClueService {

    private final TClueMapper clueMapper;


    @Override
    public PageInfo<TClue> getClueByPage(Integer current) {
        PageHelper.startPage(current, Constant.PAGE_SIZE);
        List<TClue> clueList = clueMapper.getClueByPage(new BaseQuery(), current);
        PageInfo pageInfo = new PageInfo(clueList);
        return pageInfo;
    }

    @Override
    public void importExcel(InputStream inputStream) {
        EasyExcel.read(inputStream, ClueExcel.class, new ClueExcelListener(clueMapper)).sheet().doRead();
    }

    @Override
    public TClue getClueById(Integer id) {
        TClue clue = clueMapper.getClueById(id);
        return clue;
    }

}
